package com.huahua.api.controller.entertainment;

import com.huahua.api.entity.entertainment.param.JobWorthAnalysisParam;
import com.huahua.api.service.entertainment.JobWorthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 工作价值评估控制器
 *
 * @author Huahua-Ai
 * @date 2025-01-22 10:40:00
 * @description 提供工作价值评估AI分析接口，对前端传递的评估结果进行AI总结和建议生成
 */
@Slf4j
@RestController
@RequestMapping("/entertainment/job-worth")
@RequiredArgsConstructor
public class JobWorthController {

    private final JobWorthService jobWorthService;

    /**
     * AI分析工作评估结果（流式返回）
     *
     * @param param 包含评估结果文本的参数
     * @return AI分析报告内容流
     */
    @PostMapping(value = "/analyze", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> analyzeJobEvaluation(@RequestBody JobWorthAnalysisParam param) {
        log.info("开始AI分析工作评估结果，文本长度: {}",
                param.getEvaluationText() != null ? param.getEvaluationText().length() : 0);

        return jobWorthService.analyzeJobEvaluation(param)
                .onErrorResume(error -> {
                    log.error("AI分析工作评估失败", error);
                    return Flux.just("分析评估结果时发生错误：" + error.getMessage());
                });
    }
}
